package com.wxsong.authplatform.authweb.dao.users;

import com.wxsong.authplatform.authweb.dao.BaseDao;
import com.wxsong.authplatform.authweb.model.role.Role;
import com.wxsong.authplatform.authweb.model.users.Users;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository
public class UserDao extends BaseDao {

    public Users getByUserName(String userName){
        return this.getSqlSession().selectOne("UsersMap.selectByUserName", userName);
    }

    public Users getById(Long id){
        return this.getSqlSession().selectOne("UsersMap.selectById", id);
    }

    public List<Users> list(int from, int pageSize, Map<String, Object> paramMap){
        paramMap.put("from", from);
        paramMap.put("size", pageSize);
        return this.getSqlSession().selectList("UsersMap.selectList", paramMap);
    }

    public Long count(Map<String, Object> paramMap){
        return this.getSqlSession().selectOne("UsersMap.selectCount", paramMap);
    }

    public int add(Users users){
        return this.getSqlSession().insert("UsersMap.insertUsers", users);
    }

    public int update(Map paramMap){
        return this.getSqlSession().update("UsersMap.updateUsers", paramMap);
    }

    public int delete(Long[] ids){
        return this.getSqlSession().delete("UsersMap.deleteUser", ids);
    }

    public List<Role> hasRoles(Long[] longIds) {
        return this.getSqlSession().selectList("RoleMap.selectHasRoles", longIds);
    }

    public List<Role> noRoles(Long[] longIds) {
        return this.getSqlSession().selectList("RoleMap.selectNoRoles", longIds);
    }
}
